home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / cdedit / cdrom.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  5.5 KB  |  314 lines

  1. /*************************************************************
  2.  *                                                           *
  3.  *                     file: cdrom.c                         *
  4.  *                                                           *
  5.  *************************************************************/
  6.  
  7. /*
  8.  * Copyright (C) 1988, 1989 Sun Microsystems, Inc.
  9.  */
  10.  
  11. #ifndef lint
  12. static char sccsid[] = "@(#)cdrom.c 1.4 89/12/05 Copyr 1989 Sun Microsystem, Inc.";
  13. #endif
  14.  
  15. /*
  16.  * This file contains the routine to interface with the cdrom player.
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include <sys/file.h>
  21. #include <sys/types.h>
  22. #include <sys/param.h>
  23. #include <sys/stat.h>
  24. #include <mntent.h>
  25. #include <string.h>
  26. #include <sun/dkio.h>
  27.  
  28. #include <sys/buf.h>
  29. #ifdef sun4c
  30. #include <scsi/targets/srdef.h>
  31. #else
  32. #include <sundev/srreg.h>
  33. #endif
  34.  
  35. #include <sys/time.h>
  36.  
  37. #include "cdrom.h"
  38.  
  39. int
  40. cdrom_get_relinfo(fd, track, min, sec, frame)
  41. int    fd;
  42. int *track, *min, *sec, *frame;
  43. {
  44.     struct cdrom_subchnl    sc;
  45.  
  46.     sc.cdsc_format = CDROM_MSF;
  47.     if (ioctl(fd, CDROMSUBCHNL, (struct cdrom_subchnl *)&sc) < 0) {
  48.         return 0;
  49.     }
  50.     *track = sc.cdsc_trk;
  51.     *min = sc.cdsc_reladdr.msf.minute;
  52.     *sec = sc.cdsc_reladdr.msf.second;
  53.     *frame = sc.cdsc_reladdr.msf.frame;
  54.     return 1;
  55. }
  56.  
  57. int
  58. cdrom_get_absinfo(fd, track, min, sec, frame)
  59. int    fd;
  60. int *track, *min, *sec, *frame;
  61. {
  62.     struct cdrom_subchnl    sc;
  63.  
  64.     sc.cdsc_format = CDROM_MSF;
  65.     if (ioctl(fd, CDROMSUBCHNL, (struct cdrom_subchnl *)&sc) < 0) {
  66.         return 0;
  67.     }
  68.     *track = sc.cdsc_trk;
  69.     *min = sc.cdsc_absaddr.msf.minute;
  70.     *sec = sc.cdsc_absaddr.msf.second;
  71.     *frame = sc.cdsc_absaddr.msf.frame;
  72.     return 1;
  73. }
  74.  
  75. int
  76. cdrom_play_msf(fd, msf)
  77. int fd;
  78. struct cdrom_msf msf;
  79. {
  80.         if (ioctl(fd, CDROMPLAYMSF, (struct cdrom_msf *) &msf) < 0) {
  81.       return 0;
  82.     }
  83.     return 1;
  84. }
  85.  
  86. int
  87. cdrom_play_track(fd, play_track, end_track)
  88. int    fd;
  89. int    play_track;
  90. int    end_track;
  91. {
  92.     struct    cdrom_ti    ti;
  93.  
  94.     ti.cdti_trk0 = play_track;
  95.     ti.cdti_ind0 = 1;
  96.     ti.cdti_trk1 = end_track;
  97.     ti.cdti_ind1 = 1;
  98.     if (ioctl(fd, CDROMPLAYTRKIND, (struct cdrom_ti *)&ti) < 0) {
  99.         return 0;
  100.     }
  101.     return 1;
  102. }
  103.  
  104. int
  105. cdrom_start(fd)
  106. int    fd;
  107. {
  108.     if (ioctl(fd, CDROMSTART) < 0) {
  109.         return 0;
  110.     }
  111.     return 1;
  112. }
  113.  
  114. int
  115. cdrom_stop(fd)
  116. int    fd;
  117. {
  118.     if (ioctl(fd, CDROMSTOP) < 0) {
  119.         return 0;
  120.     }
  121.     return 1;
  122. }
  123.  
  124. int
  125. cdrom_eject(fd)
  126. int    fd;
  127. {
  128.     if (ioctl(fd, CDROMEJECT) < 0) {
  129.         return 0;
  130.     }
  131.     return 1;
  132. }
  133.  
  134. int
  135. cdrom_read_tocentry(fd, entry)
  136. int    fd;
  137. struct    cdrom_tocentry    *entry;
  138. {
  139.     if (ioctl(fd, CDROMREADTOCENTRY, entry) < 0) {
  140.         return 0;
  141.     }
  142.     return 1;
  143. }
  144.     
  145. int
  146. cdrom_read_tochdr(fd, hdr)
  147. int    fd;
  148. struct    cdrom_tochdr    *hdr;
  149. {
  150.     if (ioctl(fd, CDROMREADTOCHDR, hdr) < 0) {
  151.         return 0;
  152.     }
  153.     return 1;
  154. }
  155.     
  156. int
  157. cdrom_pause(fd)
  158. int    fd;
  159. {
  160.     if (ioctl(fd, CDROMPAUSE) < 0) {
  161.         return 0;
  162.     }
  163.     return 1;
  164. }
  165.  
  166. int
  167. cdrom_resume(fd)
  168. int    fd;
  169. {
  170.     if (ioctl(fd, CDROMRESUME) < 0) {
  171.         return 0;
  172.     }
  173.     return 1;
  174. }
  175.  
  176. int
  177. cdrom_volume(fd, left_vol, right_vol)
  178. int    fd;
  179. int    left_vol;
  180. int    right_vol;
  181. {
  182.     struct    cdrom_volctrl    vol;
  183.  
  184.     vol.channel0 = left_vol;
  185.     vol.channel1 = right_vol;
  186.     if (ioctl(fd, CDROMVOLCTRL, (struct cdrom_volctrl *)&vol) < 0) {
  187.         return 0;
  188.     }
  189.     return 1;
  190. }
  191.  
  192. int
  193. cdrom_get_relmsf(fd, tmp)
  194. int    fd;
  195. struct    tm    *tmp;
  196. {
  197.     struct cdrom_subchnl    sc;
  198.  
  199.     sc.cdsc_format = CDROM_MSF;
  200.     if (ioctl(fd, CDROMSUBCHNL, (struct cdrom_subchnl *)&sc) < 0) {
  201.         return 0;
  202.     }
  203.     tmp->tm_sec = sc.cdsc_reladdr.msf.second;
  204.     tmp->tm_min = sc.cdsc_reladdr.msf.minute;
  205.     return 1;
  206. }
  207.  
  208. int
  209. cdrom_playing(fd, track)
  210. int    fd;
  211. int    *track;
  212. {
  213.     struct cdrom_subchnl    sc;
  214.  
  215.     sc.cdsc_format = CDROM_MSF;
  216.     if (ioctl(fd, CDROMSUBCHNL, (struct cdrom_subchnl *)&sc) < 0) {
  217.         return 0;
  218.     }
  219.     *track = sc.cdsc_trk;
  220.     if (sc.cdsc_audiostatus == CDROM_AUDIO_PLAY) {
  221.         return 1;
  222.     }
  223.     else {
  224.         return 0;
  225.     }
  226. }
  227.  
  228. int
  229. cdrom_paused(fd, track)
  230. int    fd;
  231. int    *track;
  232. {
  233.     struct cdrom_subchnl    sc;
  234.  
  235.     sc.cdsc_format = CDROM_MSF;
  236.     if (ioctl(fd, CDROMSUBCHNL, (struct cdrom_subchnl *)&sc) < 0) {
  237.         return 0;
  238.     }
  239.     *track = sc.cdsc_trk;
  240.     printf("in pause, status is %d\n", sc.cdsc_audiostatus);
  241.     if (sc.cdsc_audiostatus == CDROM_AUDIO_PAUSED) {
  242.         return 1;
  243.     }
  244.     else {
  245.         return 0;
  246.     }
  247. }
  248.     
  249. int
  250. mounted(rawd)
  251.     char *rawd;
  252. {
  253.     char buf[MAXPATHLEN], *cp;
  254.     struct stat st;
  255.     dev_t bdevno;
  256.     FILE *fp;
  257.     struct mntent *mnt;
  258.  
  259.     /*
  260.      * Get the block device corresponding to the raw device opened,
  261.      * and find its device number.
  262.      */
  263.     if (stat(rawd, &st) != 0) {
  264.         (void)fprintf(stderr, "Couldn't stat \"%s\": ", rawd);
  265.         perror("");
  266.         return (UNMOUNTED);
  267.     }
  268.     /*
  269.      * If this is a raw device, we have to build the block device name.
  270.      */
  271.     if ((st.st_mode & S_IFMT) == S_IFCHR) {
  272.         cp = strchr(rawd, 'r');
  273.         cp = (cp == NULL) ? NULL : ++cp;
  274.         (void)sprintf(buf, "/dev/%s", cp);
  275.         if (stat(buf, &st) != 0) {
  276.             (void)fprintf(stderr, "Couldn't stat \"%s\": ", buf);
  277.             perror("");
  278.             return (UNMOUNTED);
  279.         }
  280.     }
  281.     if ((st.st_mode & S_IFMT) != S_IFBLK) {
  282.         /*
  283.          * What is this thing? Ferget it!
  284.          */
  285.         return (UNMOUNTED);
  286.     }
  287.     bdevno = st.st_rdev & (dev_t)(~0x07);    /* Mask out partition. */
  288.  
  289.     /*
  290.      * Now go through the mtab, looking at all hsfs filesystems.
  291.      * Compare the device mounted with our bdevno.
  292.      */
  293.     if ((fp = setmntent(MOUNTED, "r")) == NULL) {
  294.         (void)fprintf(stderr, "Couldn't open \"%s\"\n", MOUNTED);
  295.         return (UNMOUNTED);
  296.     }
  297.     while ((mnt = getmntent(fp)) != NULL) {
  298.         /* avoid obvious excess stat(2)'s */
  299.         if (strcmp(mnt->mnt_type, "hsfs") != 0) {
  300.             continue;
  301.         }
  302.         if (stat(mnt->mnt_fsname, &st) != 0) {
  303.             continue;
  304.         }
  305.         if (((st.st_mode & S_IFMT) == S_IFBLK) &&
  306.             ((st.st_rdev & (dev_t)(~0x07)) == bdevno)) {
  307.             (void)endmntent(fp);
  308.             return (STILL_MOUNTED);
  309.         }
  310.     }
  311.     (void)endmntent(fp);
  312.     return (UNMOUNTED);
  313. }
  314.